package com.project.m.api.busi.db.repo.user;

import com.project.m.api.busi.db.entity.hicatcard.user.TUserCard;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface UserCardRepo extends JpaRepository<TUserCard, Long>, JpaSpecificationExecutor<TUserCard> {

    TUserCard findByUserCardId(Long userCardId);

    TUserCard findByUserCardIdAndEnable(Long userCardId, Boolean enable);

    List<TUserCard> findByUserCardNumberAndEnableOrderByUserCardIdDesc(String userCardNumber, Boolean enable);

    List<TUserCard> findByUserIdAndEnableOrderByUserCardIdDesc(Long userId, Boolean enable);

    List<TUserCard> findByUserIdAndSourceAndEnableOrderByUserCardIdDesc(Long userId, String source, Boolean enable);

    @Query("select u from TUserCard u where u.userId = ?1 and (u.status = ?2 or u.status = ?3) and u.enable = ?4 order by status asc, endTime desc")
    List<TUserCard> findByUserIdAndStatusAndEnableOrderByUserCardIdDesc(Long userId, String statusFirst, String statusSecond, Boolean enable);

    List<TUserCard> findByUserIdAndStatusInAndEnableOrderByUserCardIdDesc(Long userId, List<String> statusList, Boolean enable);

    List<TUserCard> findByUserIdAndStatusAndEnableOrderByUserCardIdDesc(Long userId, String status, Boolean enable);

    List<TUserCard> findByUserIdAndStatusAndEnableAndEndTimeGreaterThanOrderByUserCardIdDesc(Long userId, String status, Boolean enable, String endTime);

    List<TUserCard> findByUserIdAndSourceAndStatusAndEnableOrderByUserCardIdDesc(Long userId, String source, String status, Boolean enable);
}